home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 July / macformat52.iso / mac / Shareware Plus / Developers / YAAF v1.0 alpha 1 / Headers / Core / XWindow.h < prev   
Encoding:
C/C++ Source or Header  |  1997-04-24  |  7.0 KB  |  333 lines

  1. /*    XWindow.h
  2.  *
  3.  *        This is the stuff which encapsulates the window functionality
  4.  */
  5.  
  6. /*  YAAF - Yet another application framework
  7.  *  Copyright (C) 1997 William Edward Woody and In Phase Consulting
  8.  *  
  9.  *  This library is free software; you can redistribute it
  10.  *  and/or modify it under the terms of the GNU Library
  11.  *  General Public License as published by the Free Software
  12.  *  Foundation; either version 2 of the License, or any
  13.  *  later version.
  14.  *  
  15.  *  This library is distributed in the hope that it will be
  16.  *  useful, but WITHOUT ANY WARRANTY; without even the implied
  17.  *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
  18.  *  PURPOSE. See the GNU Library General Public License for
  19.  *  more details.
  20.  *  
  21.  *  You should have received a copy of the GNU Library General
  22.  *  Public License along with this library; if not, write to the
  23.  *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24.  *  Boston, MA 02111-1307, USA.
  25.  *  
  26.  *  To contact the author, either e-mail me at
  27.  *  woody@alumni.caltech.edu, or write to us at
  28.  *  
  29.  *          William Edward Woody
  30.  *          In Phase Consulting
  31.  *          1545 Ard Eevin Avenue
  32.  *          Glendale, CA 91202
  33.  */
  34.  
  35. #ifndef __XWINDOW_H__
  36. #define __XWINDOW_H__
  37.  
  38. #include <XConfig.h>
  39. #include <XView.h>
  40.  
  41. #if defined(__MWERKS__)
  42.     #if defined(macintosh)
  43.         #pragma options align=power
  44.     #endif
  45.     #if defined(__INTEL__)
  46.         #pragma pack(push,2)
  47.     #endif
  48. #endif
  49.  
  50. /************************************************************************/
  51. /*                                                                        */
  52. /*    Internal Window Storage                                                */
  53. /*                                                                        */
  54. /************************************************************************/
  55.  
  56. #if OPT_MACOS == 1
  57.  
  58. /*    MyWindowRecord
  59.  *
  60.  *        This is an extension to the WindowRecord object which provides
  61.  *    me a sleazy way to get the pointer to my XGWindow object
  62.  */
  63.  
  64. struct _MyWindowRecord {
  65.     WindowRecord        w;
  66.     XGWindow            *tw;
  67. };
  68.  
  69. #endif // OPT_MACOS
  70.  
  71.  
  72. /************************************************************************/
  73. /*                                                                        */
  74. /*    Window Management Attributes                                        */
  75. /*                                                                        */
  76. /************************************************************************/
  77.  
  78. /*
  79.  *    XGWindow types
  80.  */
  81.  
  82. #define KWinTypeDocument        0
  83. #define KWinTypeModal            1
  84. #define KWinTypeMovableModal    2
  85.  
  86. #if OPT_FLOATWINDOW == 1
  87. #define KWinTypeFloating        3
  88. #endif
  89.  
  90. /*
  91.  *    XGWindow::Attributes() values
  92.  *
  93.  *        low word is the flags
  94.  *        high word is the menu level
  95.  */
  96.  
  97. #define    KAttrNoClose            0x00000001
  98. #define KAttrNoResize            0x00000002
  99. #define KAttrHideOnSwitch        0x00000004
  100. #define KAttrNoMenu                0x00000008
  101.  
  102. #if OPT_FLOATWINDOW == 1
  103. #define KAttrFloater            0x00000010
  104. #endif
  105.  
  106. /************************************************************************/
  107. /*                                                                        */
  108. /*    Window Definition                                                    */
  109. /*                                                                        */
  110. /************************************************************************/
  111.  
  112. /*    XGSWindowInitRecord
  113.  *
  114.  *        This is the initialization record for creating my window from
  115.  *    scratch
  116.  */
  117.  
  118. struct XGSWindowInitRecord {
  119.     long                        fViewType;
  120.     
  121.     short                        windowType;
  122.     short                        windowID;
  123.     bool                        fVisible;
  124.  
  125.     /*
  126.      *    Window Size
  127.      */
  128.     
  129.     short                        screenLeft;
  130.     short                        screenTop;
  131.     short                        screenRight;
  132.     short                        screenBottom;
  133.     
  134.     /*
  135.      *    Window sizing parameters
  136.      */
  137.     
  138.     short                        minx;
  139.     short                        miny;
  140.     short                        maxx;
  141.     short                        maxy;
  142.     short                        initx;
  143.     short                        inity;
  144.     short                        zoomx;
  145.     short                        zoomy;
  146.     
  147.     /*
  148.      *    Window name
  149.      */
  150.     
  151.     char                        windowName[256];
  152. };
  153.     
  154.  
  155. /************************************************************************/
  156. /*                                                                        */
  157. /*    Window Declaration                                                    */
  158. /*                                                                        */
  159. /************************************************************************/
  160.  
  161. /*    XGWindow
  162.  *
  163.  *        This is the root class which defines windows and how they are
  164.  *    handled
  165.  */
  166.  
  167. class XGWindow : public XGView, public XGFocus {
  168.     public:
  169.         /*
  170.          *    Construction/Destruction
  171.          */
  172.         
  173.                                 XGWindow(XGSWindowInitRecord &);
  174.                                 XGWindow(XGArgStream &);
  175.         virtual                    ~XGWindow();
  176.         
  177.         /*
  178.          *    Create/Destroy
  179.          */
  180.         
  181.         static XGWindow            *Create(short);
  182.         static XGWindow            *Create(XGSWindowInitRecord &);
  183.         virtual bool            CloseWindow();
  184.         void                    SetDocument(XGDocument *d)
  185.                                     {
  186.                                         fDocument = d;
  187.                                     }
  188.         
  189.         /*
  190.          *    Initialization
  191.          */
  192.         
  193.         virtual Point            MinWindowSize();
  194.         virtual Point            MaxWindowSize();
  195.         virtual Point            InitWindowSize();
  196.         virtual Point            ZoomWindowSize();
  197.         void                    _LimitWindowSize(Point *);
  198.         
  199.         /*
  200.          *    XGView overrides
  201.          */
  202.         
  203.         void                    DoDrawView(Rect);
  204.  
  205.         /*
  206.          *    Document Support
  207.          */
  208.         
  209.         virtual bool            IsDirty();
  210.         virtual bool            DoSave();
  211.         
  212.         /*
  213.          *    Window attributes
  214.          */
  215.         
  216.         void                    GetWindowName(char *);
  217.         void                    SetWindowName(char *);
  218.         virtual short            GetMenuBarID();
  219.         
  220.         short                    GetWindowType()
  221.                                     {
  222.                                         return fWinType;
  223.                                     }
  224.         long                    _Attributes()
  225.                                     {
  226.                                         return fAttributes;
  227.                                     }
  228.  
  229.         /*
  230.          *    Window support
  231.          */
  232.         
  233.         void                    ShowWindow();
  234.         void                    HideWindow();            // Show/hide this entire window
  235.         bool                    IsShowWindow();
  236.         
  237.         static XGWindow            *GetFrontWindow();
  238.         void                    SelectWindow();
  239.         static void                GetScreenSize(Rect *);
  240.         
  241.         /*
  242.          *    Window size
  243.          */
  244.         
  245.         Point                    GetContentSize() const;
  246.         Rect                    GetContentRect() const;
  247.         
  248.         void                    SetWindowSize(Point);
  249.         void                    SetWindowPos(Point);
  250.         void                    SetWindowLocation(Rect);
  251.         
  252.         Point                    GetWindowSize() const;
  253.         Point                    GetWindowPos() const;
  254.                 
  255.         /*
  256.          *    Miscellaneous window management routines
  257.          */
  258.          
  259.         XGDocument                *_GetDocument() const
  260.                                     {
  261.                                         return fDocument;
  262.                                     }
  263.         bool                    _IsActiveWindow() const;    // Active window?
  264.         XGView                    *_CapturedView() const;
  265.         
  266.         void                    _ContentToSize(Point *) const;
  267.         void                    _ContentToSize(Rect *) const;
  268.         void                    _SizeToContent(Point *) const;
  269.         void                    _SizeToContent(Rect *) const;
  270.  
  271. #if OPT_MACOS == 1
  272.         void                    _ResetDrawing();
  273.  
  274.         static XGWindow            *_GetXGWindow(WindowPtr);
  275.         GrafPtr                    _GetGrafPtr() const
  276.                                     {
  277.                                         return (GrafPtr)(&(fWindow.w));
  278.                                     }
  279.  
  280.         bool                    _ProcessMouseDown(Point,short);
  281.         void                    _ProcessMouseMove(Point,short);
  282.         void                    _ProcessMouseUp(Point,short);
  283.         void                    _ProcessUpdateEvent(Rect);
  284.         void                    _ProcessActivateEvent(bool);
  285. #endif
  286.  
  287.         void                    _ProcessSizeEvent(void);
  288.  
  289. #if OPT_WINOS == 1
  290.         static XGWindow            *_GetXGWindow(HWND);
  291.         
  292.         bool                    IsIconic();
  293. #endif
  294.  
  295.     protected:
  296.         long                    fAttributes;
  297.  
  298.     private:
  299.         void                    IInitRecord(void);
  300.         void                    IInitWindow(XGSWindowInitRecord &);
  301.         void                    ICreateWindow(char *name, Rect *size);
  302.         
  303.         XGDocument                *fDocument;
  304.         
  305.         short                    fWinType;
  306.         short                    fWinID;
  307.         Point                    fMin;
  308.         Point                    fMax;
  309.         Point                    fInit;
  310.         Point                    fZoom;
  311.         
  312. #if OPT_MACOS == 1
  313.         XGView                    *fCapture;
  314.         _MyWindowRecord            fWindow;
  315. #endif
  316.  
  317. #if OPT_WINOS == 1
  318.     friend LRESULT CALLBACK _GChildWindowProc(HWND w, UINT msg, WPARAM wp, LPARAM lp);
  319. #endif
  320. };
  321.  
  322. #if defined(__MWERKS__)
  323.     #if defined(macintosh)
  324.         #pragma options align=reset
  325.     #endif
  326.     #if defined(__INTEL__)
  327.         #pragma pack(pop)
  328.     #endif
  329. #endif
  330.     
  331.  
  332. #endif /* __XWINDOW_H__ */
  333.